<?php
class Element{
    public $data;
    public $next;

    public function __construct($data=''){
       $this->data=$data;
        $this->next=null;
    }
}

class Queue{
    public $front;
    public $rear;

    public function __construct(){
        $this->front=$this->rear=null;
    }

    static public function enQueue($queue,$element){
        if($queue->rear==null){
            $queue->front=$queue->rear=$element;
        }else{
            $queue->rear->next=$element;
            $queue->rear=$element;
        }
    }

    static public function deQueue($queue){
        $return =$queue->front;
        $queue->front=$queue->front->next;
        return $return->data;
    }

    static public function length($queue){
        if($queue->rear==null){
            return 0;
        }
        $count=1;
        $front=$queue->front;
        while($front!=$queue->rear){
            $front=$front->next;
            $count++;
        }
        return $count;
    }

    static public function showQueue($queue){
        $front=$queue->front;
        while($front!=$queue->rear){
            echo $front->data."</br>";
            $front=$front->next;
        }
        echo $front->data."</br>";
        echo '******************************'."</br>";
    }
}

$queue=new Queue();
Queue::enQueue($queue,new Element('1'));
Queue::enQueue($queue,new Element('2'));
Queue::enQueue($queue,new Element('3'));
Queue::enQueue($queue,new Element('4'));
Queue::enQueue($queue,new Element('5'));
Queue::showQueue($queue);


echo Queue::deQueue($queue)."</br>";
echo Queue::deQueue($queue)."</br>";
echo Queue::deQueue($queue)."</br>";
echo Queue::length($queue);
?>